﻿#region Usings

using Box2DX.Collision;
using Box2DX.Common;
using Box2DX.Dynamics;

#endregion

namespace SilverBox.Physics
{
    public class BodyParameters
    {
        public BodyParameters()
        {
            IsStatic = false;
            Density = 1;
            Friction = 0.6;
            Restitution = 0.1;
            LinearDamping = 5;
            AngularDamping = 5;
            CanRotate = false;
        }

        public bool IsStatic { get; set; }
        public double Density { get; set; }
        public double Friction { get; set; }
        public double Restitution { get; set; }
        public object UserData { get; set; }
        public Vector InitialVelocity { get; set; }
        public double InitialRotationalVelocity { get; set; }
        public bool CanRotate { get; set; }
        public double LinearDamping { get; set; }
        public double AngularDamping { get; set; }

        public void SetParameters(ShapeDef shapeDef)
        {
            shapeDef.Density = IsStatic ? 0 : (float) Density;
            shapeDef.Friction = (float) Friction;
            shapeDef.Restitution = (float) Restitution;
            shapeDef.UserData = UserData;
        }

        public void SetParameters(BodyDef bodyDef)
        {
            bodyDef.LinearDamping = (float) LinearDamping;
            bodyDef.AngularDamping = (float) AngularDamping;
        }

        public void SetParameters(Body body)
        {
            body.LinearVelocity = new Vector2((float) InitialVelocity.X, (float) InitialVelocity.Y);
            body.AngularVelocity = (float) InitialRotationalVelocity;
            body.UserData = UserData;
        }
    }
}